/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx.oop;

/**
 * <p>Project: jse2303 - C4
 * <p>Powered by webrx On 2023-07-13 17:07:39
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class C5 {
    static int i = 1;

    public static void m() {
        m();
    }

    public static void m1() {
        System.out.println(i++);
        if (i < 7) {
            m1();
        }
    }

    /**
     * n 3 2 1;
     *
     * @param n
     */
    public static void m2(int n) {
        System.out.println(n);
        if (n > 1) m2(n - 1);
    }

    /**
     * 1 2 3 ... n;
     *
     * @param n
     */
    public static void m3(int n) {
        if (n > 1) m3(n - 1);
        System.out.println(n);
    }

    public static int m4(int n) {
        if (n > 1) {
            return n + m4(n - 1);
        }
        return 1;
    }


    public static void main(String[] args) {
        //m(); 死循环递归
        //m1();//根据static 变量递归
        //m2(3);//递归 3 2 1
        //m3(9);//递归输出 1 2 3 4 5 6 7 8 9
        int sum = m4(100);
        System.out.println(sum);
    }
}
